﻿class MinStack {
public:
    MinStack() {

    }
    
    void push(int val) {
        st.push(val);
        if(min_stack.empty() || val <= min_stack.top())
        {
            min_stack.push(val);
        }
    }
    
    void pop() {
        if(!st.empty())
        {
            if(min_stack.top() == st.top())
            {
                min_stack.pop();
            }
            st.pop();
        }
    }
    
    int top() {
        return st.top();
    }
    
    int getMin() {
        return min_stack.top();
    }
    private:
    stack<int> min_stack;
    stack<int> st;
};

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(val);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->getMin();
 */
 
 https://leetcode.cn/problems/min-stack/